<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8" />
    <style>
      /* 填写样式 */
    </style>
  </head>

  <body>
    <!-- 填写标签 -->
    <script type="text/javascript">
      // 填写JavaScript
      function _comma(number) {
        // 补全代码
        number = String(number)
        // 有符号，截取符号位
        let symbol = ''
        if (number[0] === '-') {
          symbol = number.slice(0, 1)
          number = number.slice(1)
        }
        // 有小数点，截取小数点后
        let dotIdx = number.indexOf('.')
        let dotNum = ''
        if (dotIdx !== -1) {
          dotNum = number.slice(dotIdx)
          number = number.slice(0, dotIdx)
        }

        var inNumArr = number.split('').reverse()
        var resArr = []
        inNumArr.forEach((item, idx) => {
          if (idx % 3 === 0 && idx !== 0) resArr.push(',')
          resArr.push(item)
        })
        resArr = resArr.reverse().join('')
        return symbol + resArr + dotNum
      }
      // console.log(_comma(-123000.1254))
    </script>
  </body>
</html>
